<?php
/**
 * @package Sj Virtue Mart
 * @version 2.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2012 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 * 
 */
defined( '_JEXEC' ) or die;

if (!empty($list)):
$image_config = array(
	'output_width'  => $params->get('item_image_width',  200),
	'output_height' => $params->get('item_image_height', 200),
	'function'		=> $params->get('item_image_function', 'resize_none'),
	'background'	=> $params->get('item_image_background', null)
);
$options=$params->toObject();
$vm_currency_display = &CurrencyDisplay::getInstance();
$count_items = count($list);

if($count_items > 0){
	if((int)$params->get('nb_cols', 3) <= 0){
			$params->set('nb_cols', 1);
	}
	if((int)$params->get('nb_rows', 3) <= 0){
			$params->set('nb_rows' ,1);
	}
	if ($count_items < $options->nb_cols) {
		$options->nb_cols = $count_items;
	}  
}


if ($options->width_module_type) {
	/* $width_item = $width_item . '%'; */
	$width_item = 100 / $options->nb_cols .'%';
	$width_module = $options->module_width . '%';
} else {
	$width_item = floor($options->module_width / $options->nb_cols) .'px';
	/* $width_item = $width_item . 'px'; */
	$width_module = $options->module_width . 'px';
}

$options->max_height_item  = str_replace("%", '', $options->max_height_item );
$options->max_height_item  = str_replace("px", '', $options->max_height_item );

if ($options->add_max_height) {
	$options->max_height_item = $options->max_height_item . 'px';
} else {
	$options->max_height_item = 'auto';
}

	ob_start();
?>	#yt-virtue-mod-<?php echo $module->id ?>,
	#yt-virtue-mod-<?php echo $module->id ?> .yt-virtuemart {
		width: <?php echo $width_module ?>;
		overflow: hidden;
	}

	#yt-virtue-mod-<?php echo $module->id ?> .yt-vm-content .vm-content-inner .vm-item{
		width: <?php echo $width_item ?> ;
		height: <?php echo  $options->max_height_item ?>;
	}
<?php 
	$style_sheet = ob_get_contents(); 
	@ob_end_clean();
	$document = &JFactory::getDocument();
	$document->addStyleDeclaration($style_sheet);
?>


	<div id="yt-virtue-mod-<?php echo $module->id; ?>">
	    <?php if ( !empty($options->pretext)): ?>
	        <div class="yt_vm_introtext"><?php echo $options->pretext; ?></div>
	    <?php endif; ?>
		    <div class="yt-virtuemart">
			        <?php include JModuleHelper::getLayoutPath($module->module, '_items');?>
		    </div>
		<?php if (!empty($options->posttext)): ?>
	          <div class="yt_vm_footertext"><?php echo $options->posttext; ?></div>
	    <?php endif; ?>
	
	</div>
<?php else: ?>
<p>Have no items! Please recheck module config!</p>
<?php endif; ?>